"""
@-*- coding: utf-8 -*-
@ python: 3.12.3
@ 创建者: JacksonCode
@ 创建时间: 2025/6/24
"""
import requests
from time import sleep
from lxml import etree
dir_name = 'imgLib'

headers = {
    'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36',
}
for page in range(1,3):
    if page == 1:
        url = 'https://sc.chinaz.com/tupian/meinvtupian.html'
    else:
        url = 'https://sc.chinaz.com/tupian/meinvtupian_%d.html'%page

    response = requests.get(url=url,headers=headers)
    response.encoding = 'utf-8'
    page_text = response.text

    tree = etree.HTML(page_text)
    #解析图片地址
    div_list = tree.xpath('/html/body/div[3]/div[2]/div')

    for div in div_list:
        img_src = "https:"+div.xpath('./img/@data-original')[0]
        title = div.xpath('./div/a/text()')[0]+'.jpg'
        #对图片链接请求
        img_data = requests.get(img_src,headers=headers).content
        with open('imgLibs/'+title,'wb') as fp:
            fp.write(img_data)
        print(title,'保存下载成功！')
